<!--
 * @Description: 
 * @Autor: dongjunhua
 * @Date: 2020-12-23 12:56:35
 * @LastEditors: dongjunhua
 * @LastEditTime: 2021-09-04 10:23:34
-->

<template>
  <div class="selection-container">
    <div class="title">
      <span class="big">:) 欢迎!</span>
      <span class="small">{{
        transitionList.length > 0
          ? '请选择一位用户:'
          : '抱歉，没有可选择的用户.'
      }}</span>
    </div>
    <div v-for="item in transitionList" :key="item.id">
      <transition name="fade-transform-bottom">
        <div
          v-show="item.show"
          class="selection"
          @click="handleSelectUser(item.id)"
        >
          <span class="svg-container">
            <svg-icon icon-class="user" />
          </span>
          <span>{{ item.name }}</span>
        </div>
      </transition>
    </div>
  </div>
</template>

<script>
import { onMounted, reactive, ref, watch } from 'vue';
export default {
  name: 'SelectUser',
  props: {
    userList: {
      type: Array,
      default: () => []
    }
  },
  setup(props, context) {
    const selectedUserId = ref(0);
    const transitionList = reactive([]);
    const handleSelectUser = id => {
      context.emit('handle-confirm', id);
    };
    watch(
      () => props.userList,
      () => {
        // console.log(props.userList);
      },
      { deep: true }
    );
    onMounted(() => {
      props.userList.forEach(u => {
        transitionList.push({
          ...u,
          show: false
        });
      });
      let i = 0;
      const interval = setInterval(() => {
        if (i < transitionList.length) {
          transitionList[i].show = true;
          i++;
        } else {
          clearInterval(interval);
        }
      }, 200);
    });
    return { props, selectedUserId, handleSelectUser, transitionList };
  }
};
</script>

<style lang="scss" scoped>
$dark_gray: #889aa4;
$light_gray: #eee;
.selection-container {
  width: 100%;

  .title {
    width: 100%;
    height: 120px;

    span {
      display: block;
      // color: $light_gray;
      font-weight: bold;
    }

    .big {
      line-height: 80px;
      font-size: 32px;
    }

    .small {
      line-height: 30px;
      font-size: 20px;
    }
  }

  .selection {
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 5px;
    // color: #454545;
    width: 100%;
    height: 45px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);

    &:hover {
      background: rgba(255, 255, 255, 0.3);
    }

    .svg-container {
      margin-left: 15px;
      margin-right: 15px;
      color: $dark_gray;
      vertical-align: middle;
    }

    // span {
    //   color: #eee;
    // }
  }
}
</style>
